/**
 * 用户输入内容验证类 正则表达式
 */

// 是否为空
export const isEmpty = (str: string): boolean => {
  return !str || str.trim() === '';
};

/**
 * 匹配 phone
 */
export const isPhone = (str: string): boolean => {
  const reg = /^((0\d{2,3}-\d{7,8})|(1[3456789]\d{9}))$/;
  return reg.test(str);
};

/**
 * 匹配 mobile
 */
export const isMobile = (str: string): boolean => {
  const reg = /^(1[3456789]\d{9})$/;
  return reg.test(str);
};

/**
 * 匹配 Email 地址
 */
export const isEmail = (str: string): boolean => {
  if (str === null || str === "") return false;
  const result = str.match(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/);
  return result !== null;
};

/**
 * 判断数值类型，包括整数和浮点数
 */
export const isNumber = (str: string): boolean => {
  return isDouble(str) || isInteger(str);
};

/**
 * 判断是否为正整数(只能输入数字[0 - 9])
 */
export const isPositiveInteger = (str: string): boolean => {
  return /(^[0-9]\d*$)/.test(str);
};

/**
 * 匹配 integer
 */
export const isInteger = (str: string): boolean => {
  if (str === null || str === "") return false;
  const result = str.match(/^[-\+]?\d+$/);
  return result !== null;
};

/**
 * 匹配 double 或 float
 */
export const isDouble = (str: string): boolean => {
  if (str === null || str === "") return false;
  const result = str.match(/^[-\+]?\d+(\.\d+)?$/);
  return result !== null;
};